﻿/*
Copyright (c) 2010 Martin Legris ( http://blog.martinlegris.com )

Permission is hereby granted, free of charge, to any person obtaining a copy of this 
software and associated documentation files (the "Software"), to deal in the Software 
without restriction, including without limitation the rights to use, copy, modify, 
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 
permit persons to whom the Software is furnished to do so, subject to the following 
conditions:

The above copyright notice and this permission notice shall be included in all copies 
or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@ignore
*/
package emusic.api
{	
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	import flash.net.URLVariables;
	import flash.utils.ByteArray;
		
	import emusic.api.clients.*;
	
	/**
	 * The starting point for using this library. This class is a singleton
	 * @usage var client:EMusicClient = EMusicClient.getInstance();
	 * @author Martin Legris ( http://blog.martinlegris.com )
	 */
	public class EMusicClient
	{
		/**
		 * The apiKey given to you by EMusic
		 */
		public static var apiKey:String = "kdfq62pcqksstkme9ws49brv";
		
		/**
		 * The base url for all communications with the server
		 */
		public static var baseUrl:String = "http://api.emusic.com/";
		
		/**
		 * The session key generated at authentication
		 */
		public static var fref:String = "";
		
		protected var _album:AlbumClient;
		protected var _artist:ArtistClient;
		//protected var _track:TrackClient;
		//protected var _label:LabelClient;
		//protected var _book:BookClient;	
		
		private static var _instance:EMusicClient;
		
		/**
		 * Client used for all Album related methods
		 */
		public function get album():AlbumClient { return _album == null ? _album = new AlbumClient() : _album; }
		
		/**
		 * Client used for all Artist related methods
		 */
		public function get artist():ArtistClient { return _artist == null ? _artist = new ArtistClient() : _artist; }
		
		/**
		 * Client used for all Track related methods
		 */
		//public function get track():TrackClient { return _track == null ? _track = new TrackClient() : _track; }
		
		/**
		 * Client used for all Label related methods
		 */
		//public function get label():LabelClient { return _label == null ? _label = new LabelClient() : _label; }
		
		/**
		 * Client used for all Book related methods
		 */
		//public function get book():BookClient { return _book == null ? _book = new BookClient() : _book; }
		
				
		/**
		 * This class being a singleton, use this function to get access to its only instance
		 * @return EMusicclient
		 * @example Example of method in use:  
		 * <listing version="3.0" > 
		 * 
		 * 
		 * </listing>
		 */
		public static function getInstance():EMusicClient
		{
			if (_instance == null)
				_instance = new EMusicClient();

			return _instance;
		}
		
		public function EMusicClient() 
		{
			super();			
		}		
	}
}